package com.google.code.swingonfire.utility.date;

import java.awt.geom.Rectangle2D;
import java.util.Calendar;

import com.google.code.swingonfire.utility.Utils;

class DateRendererConstantPart extends AbstractDateRenderPart
{

    private String text;

    public DateRendererConstantPart(DateRenderer info, String text)
    {
        super(info);

        this.text = text;
    }

    public String getText()
    {
        return text;
    }

    public void setText(String text)
    {
        if (!Utils.equals(this.text, text))
        {
            this.text = text;
            resetCachedValues();
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected Rectangle2D computeMaximumBounds(DateRendererContext context, DateFormatStyle style)
    {
        return context.getFont().getStringBounds(text, context.getFontRenderContext());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected String getValue(DateRendererContext context, DateFormatStyle style, Calendar calendar)
    {
        return text;
    }

}
